<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>角色管理</title>
    <#include "/common/link.ftl">

</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">
    <#include "/common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="role"/>
    <#include "/common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>角色编辑</h1>
        </section>
        <section class="content">
            <div class="box">
                <form class="form-horizontal" action="/role/saveOrUpdate" method="post" id="editForm">

                    <input type="hidden" name="id" value="${role.id}">
                    <div class="form-group" style="margin-top: 10px;">
                        <label class="col-sm-2 control-label">角色名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name" value="${role.name}"
                                   placeholder="请输入角色名称">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">角色编号：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="sn" value="${role.sn}" placeholder="请输入角色编号">
                        </div>
                    </div>
                    <div class="form-group " id="role">
                        <label for="role" class="col-sm-2 control-label">分配权限：</label><br/>
                        <div class="row" style="margin-top: 10px">
                            <div class="col-sm-2 col-sm-offset-2">
                                <select multiple class="form-control allPermissions" size="15" id="allPermissions">
                                    <#list permissionsAllList as tmp>
                                        <option value="${tmp.id}">${tmp.name}</option>
                                    </#list>
                                </select>
                            </div>

                            <div class="col-sm-1" style="margin-top: 60px;" align="center">
                                <div>
                                    <a type="button" class="btn btn-primary" style="margin-top: 10px" title="右移动"
                                       onclick="moveSelected('allPermissions', 'selfPermissions')">
                                        <span class="glyphicon glyphicon-menu-right"></span>
                                    </a>
                                </div>
                                <div>
                                    <a type="button" class="btn btn-primary " style="margin-top: 10px" title="左移动"
                                       onclick="moveSelected('selfPermissions', 'allPermissions')">
                                        <span class="glyphicon glyphicon-menu-left"></span>
                                    </a>
                                </div>
                                <div>
                                    <a type="button" class="btn btn-primary " style="margin-top: 10px" title="全右移动"
                                       onclick="moveAll('allPermissions', 'selfPermissions')">
                                        <span class="glyphicon glyphicon-forward"></span>
                                    </a>
                                </div>
                                <div>
                                    <a type="button" class="btn btn-primary " style="margin-top: 10px" title="全左移动"
                                       onclick="moveAll('selfPermissions', 'allPermissions')">
                                        <span class="glyphicon glyphicon-backward"></span>
                                    </a>
                                </div>
                            </div>
                            <div class="col-sm-2">
                                <select multiple class="form-control selfPermissions" size="15" name="ids"
                                        id="selfPermissions">
                                    <#list permissions as tmp>
                                        <option value="${tmp.id}">${tmp.name}</option>
                                    </#list>
                                </select>
                            </div>
                        </div>
                    </div>
                    <script>
                        var arr = [];
                        var selectOptions = $("#selfPermissions option");
                        for (var i = 0; i < selectOptions.length; i++) {
                            arr.push($(selectOptions[i]).val());
                        }
                        var allOptions = $("#allPermissions option");
                        for (var i = 0; i < allOptions.length; i++) {
                            if (arr.indexOf($(allOptions[i]).val()) != -1) {
                                $(allOptions[i]).remove();
                            }
                        }
                    </script>
                    <div class="form-group">
                        <div class="col-sm-offset-1 col-sm-6">
                            <button type="submit" class="btn btn-primary btn-submi">保存</button>
                            <a href="javascript:window.history.back()" class="btn btn-danger">取消</a>
                        </div>
                    </div>
                </form>
            </div>
        </section>
    </div>
    <#include "/common/footer.ftl">
</div>
<script>
    function moveSelected(from, to) {
        $("#" + to).append($("#" + from + ">option:selected"));
    }

    function moveAll(from, to) {
        $("#" + to).append($("#" + from + ">option"))
    }

    $("#editForm").bootstrapValidator({
        feedbackIcons: { //图标
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: { //配置要验证的字段
            name: {
                validators: { //验证的规则
                    notEmpty: { //不能为空
                        message: "姓名必填" //错误时的提示信息
                    },
                    stringLength: { //字符串的长度范围
                        min: 1,
                        max: 5
                    }
                }
            },
        }
    }).on('success.form.bv', function () { //表单所有数据验证通过后执行里面的代码]
        $("#selfPermissions option").prop("selected", true);
        //$("#editForm").submit();
    });
</script>
</body>
</html>
